#include <iostream>
#include <string>

using namespace std;


class Solution {
public:
    bool check(long long hash1[], long long hash2[], int size)
    {
        for (int i = 0; i < size; i++)
        {
            if (hash1[i] != 0 && hash1[i] > hash2[i])
                return false;
        }
        return true;
    }

    string minWindow(string s, string t) {
        long long hash1[58] = { 0 };
        for (auto e : t)
            hash1[e - 'A']++;

        long long hash2[58] = { 0 }, n = s.size(), flag = 1;
        string ans("");
        for (int left = 0, right = 0; right < n; right++)
        {
            hash2[s[right] - 'A']++;

            size_t len;
            while (check(hash1, hash2, 58))
            {
                len = right - left + 1;
                if (flag || ans.size() > len)
                {
                    flag = 0;
                    ans.clear();
                    ans += s.append(s.begin() + left, s.begin() + right);
                }
                hash2[s[left++] - 'A']--;
            }
        }

        return ans;
    }
};

int main()
{
    Solution test;
    test.minWindow("ADOBECODEBANC", "ABC");

    return 0;
}